
#include "PieceFactory.h"
#include <exception>

std::map<char, Piece*> PieceFactory::pmap_ = {
    std::pair<char, Piece*>('w', new WhitePiece()),
    std::pair<char, Piece*>('b', new BlackPiece()),
};

Piece& PieceFactory::GetPiece(const char& type)
{
  auto p = pmap_.find(type);
  if (p != pmap_.end())
    return *(p->second);
  // 没有找到合法的棋子类型。
  throw std::exception();
}

PieceFactory::~PieceFactory()
{
  for (auto& pair : pmap_) {
    delete pair.second;
    pair.second = nullptr;
  }
  pmap_.clear();
}
